#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<stdlib.h>



int main()
{
  printf("i am a process, pid:%d\n",getpid());
 
  pid_t id = fork();

  if(id == 0){
  execl("./mytest","mytest","-a","-b","-c",NULL);

  //char* const argv[] = {
  //  (char*)"ls",
  //  (char*)"-a",
  //  (char*)"-l",
  //};

  //printf("############## begin ################\n");
  //execv("/usr/bin/ls",argv);
 // execlp("ls","ls","-a","-l",NULL);
 //execl("/usr/bin/ls","ls","-a","-l",NULL);
  //execl("/usr/bin/top","top",NULL);
  printf("############## end   ################\n");
  }

  pid_t rid = waitpid(id,NULL,0);
  if(id > 0)
  {
    printf("wait success:rid:%d\n",rid);
  }
  return 0;
}




















//#define NUM 5
//typedef void(*fun_t)();
//fun_t task[NUM];
//
//void printflog()
//{
//  printf("this is log task\n");
//}
//
//void printfnet()
//{
//  printf("this is net task\n");
//}
//
//void printfnpc()
//{
//  printf("this is npc task\n");
//}
//
//void inittask()
//{
//  task[0] = printflog;
//  task[1] = printfnet;
//  task[2] = printfnpc;
//  task[3] = NULL;
//}
//
//void excutetask()
//{
//  for(int i = 0;task[i];i++) task[i]();
//}
//
//int main()
//{
//  inittask();
//  pid_t id = fork();
//  if(id == 0)
//  {
//    int cnt = 5;
//    while(cnt)
//    {
//      printf("i am child process,pid:%d ,ppid:%d\n",getpid(),getppid());
//      sleep(1);
//      cnt--;
//    }
//    exit(111);
//
//  }
//
//  int status = 0;
//  while(1)
//  {
//    pid_t rid = waitpid(id,&status,WNOHANG); 
//    if(rid > 0){
//
//      printf("wait success! rid:%d , status:%d,exit code:%d\n",rid,status,WEXITSTATUS(status));
//      break;
//    }
//    else if(rid == 0)
//    {
//      printf("father say: child is runnin,do other thing\n");
//      printf("##################begin######################\n\n");
//      excutetask();
//      printf("##################end######################\n");
//    }
//    else{
//      perror("waitpid");
//      break;
//    }
//    sleep(1);
//  }
//
//
//  
//  return 0;
////  sleep(10);
////  int status = 0;
////  pid_t rid =waitpid(id,&status,0);
////  if(WIFEXITED(status)){
////  printf("wait success! rid:%d , status:%d,exit code:%d\n",rid,status,WEXITSTATUS(status));}
////  if(rid>0){
////  printf("wait success! rid:%d , status:%d,exit singno:%d, exit code:%d\n",rid,status,status&0x7F,(status>>8)&0xFF);
////  }
////
//}
